const mongoose = require('mongoose')

/**
 * 书籍数据模型
 * 定义书籍文档的结构和验证规则
 */
const BookSchema = new mongoose.Schema(
	{
		title: {
			type: String,
			required: true
		},
		author: {
			type: String,
			required: true
		},
		publishYear: {
			type: Number,
			required: true
		}
	},
	{
		timestamps: true, // 自动添加 createdAt/updatedAt
		collection: 'bookstore' // 数据库集合
	}
)

// 创建并导出 Book 模型
module.exports = mongoose.model('Book', BookSchema)
